package com.firemoss.atonement.changewatcher.valuecomparison
{
	import flash.utils.Dictionary;
	
	import mx.collections.IList;

	public class DefaultValueComparitorFactory implements IValueComparitorFactory
	{
		private var defaultComp : DefaultEqualityComparitor;
		private var dateComp : DateEqualityComparitor;
		private var listComp : ListComparitor;
		private var dictComp : DictionaryComparitor;
		
		public function DefaultValueComparitorFactory()
		{
			defaultComp = new DefaultEqualityComparitor()
			dateComp = new DateEqualityComparitor()
			listComp = new ListComparitor()
			dictComp = new DictionaryComparitor()
				
			defaultComp.comparitorFactory = this
			dateComp.comparitorFactory = this
			listComp.comparitorFactory = this
			dictComp.comparitorFactory = this
		}
		
		public function forValues(originalValue:*, newValue:*):IValueComparitor
		{
			if ( originalValue is Date && newValue is Date )
			{
				return forDate();
			}
			
			if ( originalValue is IList && newValue is IList )
			{
				return forList();
			}
			
			if ( originalValue is Dictionary && newValue is Dictionary )
			{
				return forDictionary();
			}
			
			return forOther();
		}
		
		public function forOther():IValueComparitor
		{
			return defaultComp;
		}
		
		public function forDate():IValueComparitor
		{
			return dateComp;
		}
		
		public function forList():IValueComparitor
		{
			return listComp;
		}
		
		public function forDictionary():IValueComparitor
		{
			return dictComp;
		}
	}
}